package packetCap.CapPacket;

import jpcap.packet.ARPPacket;
import jpcap.packet.ICMPPacket;
import jpcap.packet.IPPacket;
import jpcap.packet.Packet;
import jpcap.packet.TCPPacket;
import jpcap.packet.UDPPacket;

public class myPacket {
	public int id;
	public Packet p;
	public String protocal;
	public int len;
	public String dst_ip,src_ip;
	
	public myPacket(int id,Packet p) {
		this.id = id;
		this.p = p;
		
		if(p instanceof IPPacket && ((IPPacket)p).version == 4){
			IPPacket ip = (IPPacket)p;
			switch (ip.protocol) {
			case 1:
				protocal = "ICMP";
				len = ((ICMPPacket) ip).len;
				break;

			case 6:
				protocal = "TCP";
				len = ((TCPPacket) ip).len;
				String data_tcp = new String(((TCPPacket) ip).data);
				if(data_tcp.indexOf("HTTP") != -1){
					protocal = "HTTP";
				}
				break;
			case 17:
				protocal = "UDP";
				len = ((UDPPacket) ip).len;
				String data = new String(((UDPPacket) ip).data);
				if(data.indexOf("M-SEARCH") != -1 || data.indexOf("NTS: ssdp:alive") != -1|| data.indexOf("NTS: ssdp:byebye") != -1){
					protocal = "SSDP";
				}
				break;

			}
			
			dst_ip = ip.dst_ip.toString();
			src_ip = ip.src_ip.toString();
			
		}else if(p instanceof ARPPacket){
			ARPPacket arp = (ARPPacket)p;
			protocal = "ARP";
			len = arp.len;
			
		}
		
		
	}
}
